from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2022-03-29 14:02:24.729361
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Tue, 29, Mar, 2022
Time: 14:02:29
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -48.7423
Nobs: 610.000 HQIC: -49.1402
Log likelihood: 7365.05 FPE: 3.53742e-22
AIC: -49.3935 Det(Omega_mle): 3.05584e-22
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.346084 0.065937 5.249 0.000
L1.Burgenland 0.106335 0.040310 2.638 0.008
L1.Kärnten -0.110444 0.021083 -5.239 0.000
L1.Niederösterreich 0.194399 0.084245 2.308 0.021
L1.Oberösterreich 0.116840 0.083004 1.408 0.159
L1.Salzburg 0.259963 0.042745 6.082 0.000
L1.Steiermark 0.039849 0.056419 0.706 0.480
L1.Tirol 0.103456 0.045536 2.272 0.023
L1.Vorarlberg -0.066944 0.040211 -1.665 0.096
L1.Wien 0.017495 0.073929 0.237 0.813
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.052268 0.141587 0.369 0.712
L1.Burgenland -0.037730 0.086558 -0.436 0.663
L1.Kärnten 0.042065 0.045272 0.929 0.353
L1.Niederösterreich -0.201950 0.180902 -1.116 0.264
L1.Oberösterreich 0.454430 0.178237 2.550 0.011
L1.Salzburg 0.283048 0.091787 3.084 0.002
L1.Steiermark 0.113001 0.121151 0.933 0.351
L1.Tirol 0.306040 0.097781 3.130 0.002
L1.Vorarlberg 0.026725 0.086346 0.310 0.757
L1.Wien -0.029139 0.158749 -0.184 0.854
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.196889 0.033699 5.843 0.000
L1.Burgenland 0.088787 0.020601 4.310 0.000
L1.Kärnten -0.007131 0.010775 -0.662 0.508
L1.Niederösterreich 0.243262 0.043056 5.650 0.000
L1.Oberösterreich 0.159752 0.042421 3.766 0.000
L1.Salzburg 0.040458 0.021846 1.852 0.064
L1.Steiermark 0.027308 0.028835 0.947 0.344
L1.Tirol 0.082233 0.023272 3.534 0.000
L1.Vorarlberg 0.054026 0.020551 2.629 0.009
L1.Wien 0.116405 0.037783 3.081 0.002
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.117139 0.033721 3.474 0.001
L1.Burgenland 0.042607 0.020615 2.067 0.039
L1.Kärnten -0.012918 0.010782 -1.198 0.231
L1.Niederösterreich 0.173064 0.043084 4.017 0.000
L1.Oberösterreich 0.334196 0.042449 7.873 0.000
L1.Salzburg 0.100381 0.021860 4.592 0.000
L1.Steiermark 0.112566 0.028853 3.901 0.000
L1.Tirol 0.089860 0.023288 3.859 0.000
L1.Vorarlberg 0.060496 0.020564 2.942 0.003
L1.Wien -0.017710 0.037808 -0.468 0.639
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.124020 0.063189 1.963 0.050
L1.Burgenland -0.045819 0.038630 -1.186 0.236
L1.Kärnten -0.045305 0.020205 -2.242 0.025
L1.Niederösterreich 0.138417 0.080734 1.714 0.086
L1.Oberösterreich 0.160599 0.079545 2.019 0.043
L1.Salzburg 0.285046 0.040963 6.959 0.000
L1.Steiermark 0.058762 0.054068 1.087 0.277
L1.Tirol 0.158547 0.043638 3.633 0.000
L1.Vorarlberg 0.097432 0.038535 2.528 0.011
L1.Wien 0.071178 0.070848 1.005 0.315
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.073329 0.049360 1.486 0.137
L1.Burgenland 0.025007 0.030176 0.829 0.407
L1.Kärnten 0.053228 0.015783 3.373 0.001
L1.Niederösterreich 0.192190 0.063065 3.047 0.002
L1.Oberösterreich 0.329901 0.062136 5.309 0.000
L1.Salzburg 0.035931 0.031998 1.123 0.261
L1.Steiermark 0.009297 0.042235 0.220 0.826
L1.Tirol 0.120368 0.034088 3.531 0.000
L1.Vorarlberg 0.066021 0.030102 2.193 0.028
L1.Wien 0.096403 0.055343 1.742 0.082
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.170541 0.059525 2.865 0.004
L1.Burgenland 0.005759 0.036390 0.158 0.874
L1.Kärnten -0.065907 0.019033 -3.463 0.001
L1.Niederösterreich -0.105157 0.076054 -1.383 0.167
L1.Oberösterreich 0.206217 0.074933 2.752 0.006
L1.Salzburg 0.054989 0.038588 1.425 0.154
L1.Steiermark 0.247515 0.050933 4.860 0.000
L1.Tirol 0.502020 0.041108 12.212 0.000
L1.Vorarlberg 0.064155 0.036301 1.767 0.077
L1.Wien -0.077519 0.066741 -1.161 0.245
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.159251 0.065988 2.413 0.016
L1.Burgenland -0.002435 0.040342 -0.060 0.952
L1.Kärnten 0.062759 0.021100 2.974 0.003
L1.Niederösterreich 0.168864 0.084312 2.003 0.045
L1.Oberösterreich -0.056909 0.083069 -0.685 0.493
L1.Salzburg 0.208645 0.042778 4.877 0.000
L1.Steiermark 0.139230 0.056464 2.466 0.014
L1.Tirol 0.057189 0.045572 1.255 0.210
L1.Vorarlberg 0.146830 0.040243 3.649 0.000
L1.Wien 0.119490 0.073987 1.615 0.106
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.390237 0.038838 10.048 0.000
L1.Burgenland -0.004463 0.023743 -0.188 0.851
L1.Kärnten -0.020858 0.012418 -1.680 0.093
L1.Niederösterreich 0.202801 0.049622 4.087 0.000
L1.Oberösterreich 0.230450 0.048891 4.714 0.000
L1.Salzburg 0.036763 0.025178 1.460 0.144
L1.Steiermark -0.015846 0.033232 -0.477 0.633
L1.Tirol 0.089130 0.026822 3.323 0.001
L1.Vorarlberg 0.051045 0.023685 2.155 0.031
L1.Wien 0.043754 0.043546 1.005 0.315
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.036438 0.107562 0.170686 0.137545 0.099702 0.080561 0.034231 0.209727
Kärnten 0.036438 1.000000 -0.026489 0.130778 0.048884 0.084970 0.443583 -0.066775 0.089439
Niederösterreich 0.107562 -0.026489 1.000000 0.312941 0.119462 0.273739 0.067405 0.153722 0.292600
Oberösterreich 0.170686 0.130778 0.312941 1.000000 0.212134 0.295814 0.166389 0.136979 0.238628
Salzburg 0.137545 0.048884 0.119462 0.212134 1.000000 0.122945 0.092213 0.104797 0.123900
Steiermark 0.099702 0.084970 0.273739 0.295814 0.122945 1.000000 0.134540 0.107436 0.035827
Tirol 0.080561 0.443583 0.067405 0.166389 0.092213 0.134540 1.000000 0.064933 0.150636
Vorarlberg 0.034231 -0.066775 0.153722 0.136979 0.104797 0.107436 0.064933 1.000000 -0.004151
Wien 0.209727 0.089439 0.292600 0.238628 0.123900 0.035827 0.150636 -0.004151 1.000000